# - Try to find the  FriBidi
# Once done this will define
#
#  FRIBIDI_FOUND - system has FriBidi
#  FRIBIDI_INCLUDE_DIR - The include directory to use for the fribidi headers
#  FRIBIDI_LIBRARIES - Link these to use FriBidi
#  FRIBIDI_DEFINITIONS - Compiler switches required for using FriBidi

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

if (FRIBIDI_LIBRARIES AND FRIBIDI_INCLUDE_DIR)

  # in cache already
  set(FRIBIDI_FOUND TRUE)

else (FRIBIDI_LIBRARIES AND FRIBIDI_INCLUDE_DIR)

  if (NOT MSVC)
    # use pkg-config to get the directories and then use these values
    # in the FIND_PATH() and FIND_LIBRARY() calls
    find_package(PkgConfig)
    pkg_check_modules(PC_FRIBIDI fribidi)

    set(FRIBIDI_DEFINITIONS ${PC_FRIBIDI_CFLAGS_OTHER})
  endif (NOT MSVC)

  find_path(FRIBIDI_INCLUDE_DIR fribidi.h
    PATHS
    ${PC_FRIBIDI_INCLUDEDIR}
    ${PC_FRIBIDI_INCLUDE_DIRS}
  )

  find_library(FRIBIDI_LIBRARIES NAMES fribidi
    PATHS
    ${PC_FRIBIDI_LIBDIR}
    ${PC_FRIBIDI_LIBRARY_DIRS}
  )

  include(FindPackageHandleStandardArgs)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(FriBidi DEFAULT_MSG FRIBIDI_LIBRARIES FRIBIDI_INCLUDE_DIR )
  
  mark_as_advanced(FRIBIDI_LIBRARIES FRIBIDI_INCLUDE_DIR)

endif (FRIBIDI_LIBRARIES AND FRIBIDI_INCLUDE_DIR)
